package org.zanateh.wargame.graphics;

import static org.anddev.andengine.util.constants.Constants.VERTEX_INDEX_X;
import static org.anddev.andengine.util.constants.Constants.VERTEX_INDEX_Y;

import org.anddev.andengine.collision.RectangularShapeCollisionChecker;
import org.anddev.andengine.collision.ShapeCollisionChecker;
import org.anddev.andengine.entity.shape.RectangularShape;

public class HexagonalShapeCollisionChecker extends ShapeCollisionChecker {
	// ===========================================================
	// Constants
	// ===========================================================

	private static final int HEXAGONALSHAPE_VERTEX_COUNT = 6;
	private static final int LINE_VERTEX_COUNT = 2;

	private static final float[] VERTICES_CONTAINS_TMP = new float[2 * HEXAGONALSHAPE_VERTEX_COUNT];
	private static final float[] VERTICES_COLLISION_TMP_A = new float[2 * HEXAGONALSHAPE_VERTEX_COUNT];
	private static final float[] VERTICES_COLLISION_TMP_B = new float[2 * HEXAGONALSHAPE_VERTEX_COUNT];

	public static boolean checkContains(final HexagonDrawable pHexagon, final float pX, final float pY) {
		fillVertices(pHexagon, VERTICES_CONTAINS_TMP);
		return ShapeCollisionChecker.checkContains(VERTICES_CONTAINS_TMP, 2 * HEXAGONALSHAPE_VERTEX_COUNT, pX, pY);
	}

	public static void fillVertices(final HexagonDrawable pHexagon, final float[] pVertices) {
		HexagonVertexBuffer buf = pHexagon.getVertexBuffer();
		for(int i = 0; i < HEXAGONALSHAPE_VERTEX_COUNT * 2; ++i) {
			pVertices[i] = buf.lookup(i);
		}

		pHexagon.getLocalToSceneTransformation().transform(pVertices);
	}

}
